package cn.itcast.order.service;

import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import cn.itcast.order.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Service
public class OrderService {

    @Resource
    private OrderMapper orderMapper;

    @Resource
    private RestTemplate restTemplate;

    public Order queryOrderById(Long orderId) {
        // 1.根据id查询订单
        Order order = orderMapper.findById(orderId);
        //2.利用RestTemplate发送http请求，查询用户
        User user = restTemplate.getForObject("http://userservice/user/"+order.getUserId(), User.class);
        //3.将查询的用户数据存放到Order.user属性中
        order.setUser(user);
        //4.返回
        return order;
    }
}
